package com.sanen.flyer.entity;

import com.sanen.flyer.common.Constant;
import com.sanen.flyer.main.Game;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @author wsse
 * @date 2018-09-06 10:50
 */
public class GameBackground extends FlyObject {
    BufferedImage img;
    private int bgx, bg1y, bg2y;
    int windowWidth;
    int windowHeight;
    public GameBackground(BufferedImage image) {
        this.img = image;
        bgx = 0;
//        bg1y = Game.HEIGHT - img.getHeight();
//        bg2y = bg1y - img.getHeight();
        this.speedy=0.3;
        windowWidth= Constant.getWindowWidth();
        windowHeight=Constant.getWindowHeight();
        width=windowWidth;
        height=(int)(windowWidth*1.0/img.getWidth()*img.getHeight());
        bg1y = windowHeight - height;
        bg2y = bg1y - height;
        System.out.println(windowWidth);
        System.out.println(bg1y+","+bg2y+","+width+","+height);
    }


    @Override
    public void draw(Graphics g) {
        g.drawImage(img, bgx, bg1y, width,height,null);
        g.drawImage(img, bgx, bg2y, width,height,null);
    }

    @Override
    public void logic() {
        move();
        if (bg1y>windowHeight-10){
            bg1y = bg2y - height;
        }
        if (bg2y>windowHeight-10){
            bg2y = bg1y - height;
        }
    }

    @Override
    public void move() {
        bg1y+=(int)speedy;
        bg2y+=(int)speedy;
        sumy+=speedy-(int)speedy;
        if (sumy>=1){
            bg1y+=1;
            bg2y+=1;
            sumy--;
        }
    }

    @Override
    public boolean outOfBounds() {
        return false;
    }

    @Override
    public boolean touchBounds() {
        return false;
    }

}
